﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using humocloud.Configuration;
using humocloud.Web;

namespace humocloud.EntityFrameworkCore
{
    /* This class is needed to run "dotnet ef ..." commands from command line on development. Not used anywhere else */
    public class humocloudDbContextFactory : IDesignTimeDbContextFactory<humocloudDbContext>
    {
        public humocloudDbContext CreateDbContext(string[] args)
        {
            var builder = new DbContextOptionsBuilder<humocloudDbContext>();
            var configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder());

            humocloudDbContextConfigurer.Configure(builder, configuration.GetConnectionString(humocloudConsts.ConnectionStringName));

            return new humocloudDbContext(builder.Options);
        }
    }
}
